package com.yanqu.road.entity.activity.peakseacraft.config;


import com.yanqu.road.entity.activity.ActivityConfig;
import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.seacraft.config.*;
import com.yanqu.road.entity.enums.eActivityConfigType;
import com.yanqu.road.utils.date.DateHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @Description 海上争霸 之南海丝路 配置
 * @Author cwq
 * @Data 2022/1/20 10:12
 */
public class PeakSeacraftActivityConfig {

    private ActivityInfo activityInfo;

    /**
     * 小队人数
     */
    private static int teamNum = 6;

    /**
     * 宝库格子数
     */
    private static int pubGribNum = 9;

    /**
     * 捐献道具id
     */
    private int SEACRAFT_CRAFT_DONATE_ITEMS;

    public List<Integer> donateList = new ArrayList<>();

    /**
     * 匹配排名前后n名次
     */
    private int SEACRAFT_CRAFT_MATCH_NUM;
    /**
     * 门客小队初始突袭次数
     */
    private int SEACRAFT_CRAFT_CHARGE_TIME;
    /**
     * 主角初始突袭次数
     */
    private int SEACRAFT_CRAFT_CHARGE_SINGLE_TIME;
    /**
     * 门客小队回复攻击次数道具id
     */
    private int SEACRAFT_CRAFT_ATTACK_ITEM_ID;
    /**
     * 门客小队回复攻击次数需要消耗道具数量,数字个数=回复次数
     */
    private String SEACRAFT_CRAFT_ATTACK_ITEM_COST;

    public List<Integer> attackItemCostList = new ArrayList<>();

    /**
     * 首次购买消耗
     */
    private String SEACRAFT_CRAFT_BUFF_COST_FIRST;

    public List<Integer> firstBuyCostList = new ArrayList<>();

    /**
     * 购买消耗
     */
    private String SEACRAFT_CRAFT_BUFF_COST;

    public List<Integer> buyCostList = new ArrayList<>();

    /**
     * 购买buff 需要消耗最大的元宝数量
     */
    public int maxCostNum = 0;

    /**
     * 首次增幅（百分比）
     */
    private String SEACRAFT_CRAFT_BUFF_FIRSTADD;

    public List<Integer> firstAddBuffList = new ArrayList<>();
    /**
     * 正常增幅（百分比）
     */
    private String SEACRAFT_CRAFT_BUFF_ADD;

    public List<Integer> addBuffList = new ArrayList<>();

    /**
     * 连胜次数后获得连胜奖励
     */
    private int SEACRAFT_CRAFT_REWARD_COMBONUM;
    /**
     * 胜利对决奖励|失败对决奖励
     */
    private String SEACRAFT_CRAFT_REWARD_END;

    /**
     * 战斗奖励 0 胜利 1失败
     */
    public List<String> battleRewardList = new ArrayList<>();

    /**
     * 一键挑战解锁条件（次）
     */
    private int SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_NUM;
    /**
     * 一键挑战解锁条件（VIP）
     */
    private int SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_VIP;
    /**
     * 一键挑战时间限制（活动结束前n分钟不允许使用）
     */
    private int SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_TIME_FINISH;
    /**
     * 每次击败门客扣除船只血量
     */
    private int SEACRAFT_CRAFT_KILL_POINT;

    /**
     * 扳手道具id
     */
    private int SEACRAFT_CRAFT_WRENCH_ITEM_ID;

    /**
     * 炸药道具id
     */
    private int SEACRAFT_CRAFT_FIRE_ITEM_ID;

    /**
     * 航海勋章id
     */
    private int SEACRAFT_CRAFT_SCORE_ITEM_ID;

    /**
     * 突袭可获得海战勋章数量
     */
    private int SEACRAFT_CRAFT_CHARGE_SCORE;

    /**
     * 进攻可获得海战勋章数量=参数1+参数2*本次进攻消耗的进攻道具数量
     */
    private String SEACRAFT_CRAFT_ATTACK_SCORE;

    public List<Integer> attackScoreList = new ArrayList<>();
    /**
     * 炸药的伤害系数
     */
    private int SEACRAFT_CRAFT_FIRE_EFFECT;

    /**
     * 备战期开启时间(h)，格式：开启时间,结束时间,限制数量
     */
    private String SEACRAFT_CRAFT_BEIZHAN_TIME;

    /**
     * 报名期结束时间,活动开始后的秒数
     */
    public int registrationEndTime;

    /**
     * 0:备战期开始时间   1备战期结束时间 s
     */
    public List<Long> pretimeList = new ArrayList<>();

    /**
     * 海上争霸开启时间(h)，格式：开启时间,结束时间,每组晋级数,击败门客积分|.....|..
     */
    private String SEACRAFT_CRAFT_ZHENGBA_TIME;

    /**
     * 每轮开放的时间 0:开放的开始时间 1开放的结束时间 2 本轮晋级的数量
     */
    public List<Integer[]> roundTimeList = new ArrayList<>();

    /**
     * 海上争霸每小时路程长度。阶段路程总长度=阶段时间*每小时路程长度
     */
    private Long SEACRAFT_CRAFT_DISTANCE;

    /**
     * 海上争霸船只初始属性，初始生命值系数|初始速度,均为百分数；船只生命值=生命值系数*商会人数*(1+等级加成)
     */
    private String SEACRAFT_CRAFT_SHIP_FIRST;

    /**
     * 单次战胜N名防守成员后，播放跑马灯效果
     */
    private int SEACRAFT_CRAFT_KILL_REPORT;
    /**
     * 海上争霸保底速度参数。触发保底速度血量=最大血量*参数/1000，保底速度=最大速度*参数/1000
     */
    private int SEACRAFT_CRAFT_SPEED_MIN;

    /**
     * 造成伤害前n名显示进攻路线|受到伤害前n名显示进攻路线
     */
    private String SEACRAFT_CRAFT_SHIP_ATTACK_RANK;

    /**
     * 展示前n名已到达的船只
     */
    private int SEACRAFT_CRAFT_SHIP_DISPLAY_NUM;

    /**
     * 修理工配置，恢复血量千分比|修理时间间隔（秒）
     */
    private String SEACRAFT_CRAFT_REPAIR_PARAM;

    /**
     * 修理工配置，恢复血量千分比|修理时间间隔（秒）
     */
    private List<Integer> repairParam = new ArrayList<>();

    /**
     * 船桨道具id，低级船桨|中级船桨|高级船桨|特级船桨
     */
    private String SEACRAFT_CRAFT_PADDLE_ITEM_ID;

    /**
     * 船桨加速参数，加速幅度百分数(m/s);加速时间(秒)|加速幅度百分数(m/s);加速时间(秒)
     */
    private String SEACRAFT_CRAFT_PADDLE_ITEM_PARAM;

    /**
     * 最多只能同时存在n条船桨效果
     */
    private int SEACRAFT_CRAFT_SPEED_UP_LIMIT;

    /**
     * 每组数量限制
     */
    private int GROUP_PERNUM = 32;

    /**
     * 商船日志保留条数
     */
    private int SEACRAFT_CRAFT_SHIP_NUM = 100;

    /**
     * 跨服聊天保留记录数
     */
    private int SEACRAFT_CRAFT_TALK_NUM = 100;
    /**
     * 膜拜奖励
     */
    private String WORSHIP_REWARD;

    /**
     * 船桨道具
     */
    private List<Integer> paddleItemIdList = new ArrayList<>();

    /**
     * 船桨加速参赛
     */
    private List<String> paddleItemParamList = new ArrayList<>();

    private List<Integer> attackRankList = new ArrayList<>();

    public List<Integer> shipFirstList = new ArrayList<>();

    /**
     * 竞猜数量
     */
    private int guessNum;

    private List<SeacraftSouthSeaShipConfig> shipList = new ArrayList<>();
    private List<PeakSeacraftLastGuessConfig> guessList = new ArrayList<>();
    private List<SeacraftSouthSeaFloorConfig> floorList = new ArrayList<>();
    private Map<Integer, SeacraftSouthSeaFloorConfig> floorMap = new ConcurrentHashMap<>();
    private List<SeacraftSouthSeaBattleConfig> battleList = new ArrayList<>();
    private List<PeakSeacraftDonateConfig> silverDonateList = new ArrayList<>();
    //k:area*100+round
    private Map<Integer, List<PeakSeacraftRoundScoreConfig>> roundScoreMap = new ConcurrentHashMap<>();

    /**
     * K:round : k：进攻方式 v：排名奖励集合
     */
    private Map<Integer, Map<Integer, List<SeacraftSouthSeaBattleRankInfo>>> rankBattleListMap = new ConcurrentHashMap<>();
    /**
     * 竞猜数量 k:南海丝路轮次 1 2  每轮竞猜联盟的最高数量
     */
    private Map<Integer, Integer> guessUnionNumMap = new ConcurrentHashMap<>();

    /**
     * 当前回合 最后的第三回合跑完会变成4，要注意
     */
    private int curRound = 0;
    /**
     * 下一次轮的变化时间
     */
    private long nextRoundTime = 0;


    public PeakSeacraftActivityConfig(ActivityInfo activityInfo) {
        this.activityInfo = activityInfo;
    }

    public ActivityInfo getActivityInfo() {
        return activityInfo;
    }

    /**
     * 初始化活动配置
     *
     * @return
     */
    public void parseConfig(Map<String, ActivityConfig> activityConfigMap) {
        SEACRAFT_CRAFT_DONATE_ITEMS = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_DONATE_ITEMS.getName()).getIntValue();
        SEACRAFT_CRAFT_MATCH_NUM = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_MATCH_NUM.getName()).getIntValue();
        SEACRAFT_CRAFT_CHARGE_TIME = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_CHARGE_TIME.getName()).getIntValue();
        SEACRAFT_CRAFT_CHARGE_SINGLE_TIME = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_CHARGE_SINGLE_TIME.getName()).getIntValue();
        SEACRAFT_CRAFT_ATTACK_ITEM_ID = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_ATTACK_ITEM_ID.getName()).getIntValue();
        SEACRAFT_CRAFT_ATTACK_ITEM_COST = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_ATTACK_ITEM_COST.getName()).getValue();
        SEACRAFT_CRAFT_BUFF_COST_FIRST = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_BUFF_COST_FIRST.getName()).getValue();
        SEACRAFT_CRAFT_BUFF_COST = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_BUFF_COST.getName()).getValue();
        SEACRAFT_CRAFT_BUFF_FIRSTADD = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_BUFF_FIRSTADD.getName()).getValue();
        SEACRAFT_CRAFT_BUFF_ADD = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_BUFF_ADD.getName()).getValue();
//        SEACRAFT_CRAFT_REWARD_WIN = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_REWARD_WIN.getName()).getValue();
        SEACRAFT_CRAFT_REWARD_COMBONUM = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_REWARD_COMBONUM.getName()).getIntValue();
        SEACRAFT_CRAFT_REWARD_END = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_REWARD_END.getName()).getValue();
        SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_NUM = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_NUM.getName()).getIntValue();
        SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_VIP = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_VIP.getName()).getIntValue();
        SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_TIME_FINISH = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_TIME_FINISH.getName()).getIntValue();
        SEACRAFT_CRAFT_KILL_POINT = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_KILL_POINT.getName()).getIntValue();
        SEACRAFT_CRAFT_WRENCH_ITEM_ID = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_WRENCH_ITEM_ID.getName()).getIntValue();
        SEACRAFT_CRAFT_FIRE_ITEM_ID = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_FIRE_ITEM_ID.getName()).getIntValue();
        SEACRAFT_CRAFT_SCORE_ITEM_ID = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_SCORE_ITEM_ID.getName()).getIntValue();
        SEACRAFT_CRAFT_CHARGE_SCORE = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_CHARGE_SCORE.getName()).getIntValue();
        SEACRAFT_CRAFT_ATTACK_SCORE = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_ATTACK_SCORE.getName()).getValue();
        SEACRAFT_CRAFT_BEIZHAN_TIME = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_BEIZHAN_TIME.getName()).getValue();
        SEACRAFT_CRAFT_ZHENGBA_TIME = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_ZHENGBA_TIME.getName()).getValue();
        SEACRAFT_CRAFT_DISTANCE = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_DISTANCE.getName()).getLongValue();
        SEACRAFT_CRAFT_SHIP_FIRST = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_SHIP_FIRST.getName()).getValue();
        SEACRAFT_CRAFT_KILL_REPORT = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_KILL_REPORT.getName()).getIntValue();
        SEACRAFT_CRAFT_SPEED_MIN = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_SPEED_MIN.getName()).getIntValue();
        SEACRAFT_CRAFT_SHIP_ATTACK_RANK = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_SHIP_ATTACK_RANK.getName()).getValue();
        SEACRAFT_CRAFT_SHIP_DISPLAY_NUM = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_SHIP_DISPLAY_NUM.getName()).getIntValue();
        SEACRAFT_CRAFT_REPAIR_PARAM = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_REPAIR_PARAM.getName()).getValue();
        SEACRAFT_CRAFT_PADDLE_ITEM_ID = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_PADDLE_ITEM_ID.getName()).getValue();
        SEACRAFT_CRAFT_PADDLE_ITEM_PARAM = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_PADDLE_ITEM_PARAM.getName()).getValue();
        SEACRAFT_CRAFT_SPEED_UP_LIMIT = activityConfigMap.get(eActivityConfigType.SEACRAFT_CRAFT_SPEED_UP_LIMIT.getName()).getIntValue();
        GROUP_PERNUM = activityConfigMap.get("GROUP_PERNUM").getIntValue();
        SEACRAFT_CRAFT_SHIP_NUM = activityConfigMap.get("SEACRAFT_CRAFT_SHIP_NUM").getIntValue();
        SEACRAFT_CRAFT_TALK_NUM = activityConfigMap.get("SEACRAFT_CRAFT_TALK_NUM").getIntValue();
        WORSHIP_REWARD = activityConfigMap.get("WORSHIP_REWARD").getValue();


        attackItemCostList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_ATTACK_ITEM_COST, "\\|");
        firstBuyCostList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_BUFF_COST_FIRST, "\\|");
        buyCostList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_BUFF_COST, "\\|");
        battleRewardList = StringUtils.stringToStringList(SEACRAFT_CRAFT_REWARD_END, "\\|");
        attackScoreList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_ATTACK_SCORE, "\\|");
        attackRankList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_SHIP_ATTACK_RANK, "\\|");
        repairParam = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_REPAIR_PARAM, "\\|");
        paddleItemIdList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_PADDLE_ITEM_ID, "\\|");
        paddleItemParamList = StringUtils.stringToStringList(SEACRAFT_CRAFT_PADDLE_ITEM_PARAM, "\\|");

        // 购买buff 需要消耗最大的元宝数量
        firstBuyCostList.forEach(e -> {
            if (e > maxCostNum) {
                maxCostNum = e;
            }
        });
        buyCostList.forEach(e -> {
            if (e > maxCostNum) {
                maxCostNum = e;
            }
        });
        firstAddBuffList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_BUFF_FIRSTADD, "\\|");
        addBuffList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_BUFF_ADD, "\\|");

        List<Integer> tempPreTimeList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_BEIZHAN_TIME, ";");
        pretimeList.add(tempPreTimeList.get(0) * DateHelper.HOUR_SECONDS);
        pretimeList.add(tempPreTimeList.get(1) * DateHelper.HOUR_SECONDS);
        pretimeList.add(Long.valueOf(tempPreTimeList.get(2)));//报名期人数


        String[] roundTimeListStr = SEACRAFT_CRAFT_ZHENGBA_TIME.split("\\|");
        for (String str : roundTimeListStr) {
            List<Integer> paramStrList = StringUtils.stringToIntegerList(str, ";");
            Integer[] roundTime = new Integer[4];
            roundTime[0] = (int) (paramStrList.get(0) * DateHelper.HOUR_SECONDS);//战斗开始时间
            roundTime[1] = (int) (paramStrList.get(1) * DateHelper.HOUR_SECONDS);//战斗结束时间
            roundTime[2] = paramStrList.get(2);//每组前N名晋级下一个海域
            roundTime[3] = paramStrList.get(3);//击败门客积分
            roundTimeList.add(roundTime);
        }

        // 解析报名期结束时间
        registrationEndTime = pretimeList.get(0).intValue();

        shipFirstList = StringUtils.stringToIntegerList(SEACRAFT_CRAFT_SHIP_FIRST, "\\|");

        for (PeakSeacraftLastGuessConfig guessConfig : guessList) {
            if (guessConfig.getGuessRankCount() > guessNum) {
                guessNum = guessConfig.getGuessRankCount();
            }
        }


        floorList.forEach(e -> {
            floorMap.put(e.getFloor(), e);
        });
        // k:round k:type k rank
        Map<Integer, Map<Integer, Map<Integer, List<SeacraftSouthSeaBattleConfig>>>> tempRankBattleMap = new HashMap<>();
        battleList.forEach(e -> {
            Map<Integer, Map<Integer, List<SeacraftSouthSeaBattleConfig>>> roundMap = tempRankBattleMap.get(e.getRound());
            if (roundMap == null) {
                roundMap = new HashMap<>();
                tempRankBattleMap.put(e.getRound(), roundMap);
            }
            Map<Integer, List<SeacraftSouthSeaBattleConfig>> typeMap = roundMap.get(e.getType());
            if (typeMap == null) {
                typeMap = new HashMap<>();
                roundMap.put(e.getType(), typeMap);
            }
            List<SeacraftSouthSeaBattleConfig> rankList = typeMap.get(e.getRank());
            if (rankList == null) {
                rankList = new ArrayList<>();
                typeMap.put(e.getRank(), rankList);
            }
            rankList.add(e);
        });

        for (Map.Entry<Integer, Map<Integer, Map<Integer, List<SeacraftSouthSeaBattleConfig>>>> entry : tempRankBattleMap.entrySet()) {
            int round = entry.getKey();
            Map<Integer, List<SeacraftSouthSeaBattleRankInfo>> roundMap = rankBattleListMap.get(round);
            if (roundMap == null) {
                roundMap = new HashMap<>();
                rankBattleListMap.put(round, roundMap);
            }
            for (Map.Entry<Integer, Map<Integer, List<SeacraftSouthSeaBattleConfig>>> rankEntry : entry.getValue().entrySet()) {
                int type = rankEntry.getKey();
                List<SeacraftSouthSeaBattleRankInfo> rankInfoList = roundMap.get(type);
                if (rankInfoList == null) {
                    rankInfoList = new ArrayList<>();
                    roundMap.put(type, rankInfoList);
                }
                for (Map.Entry<Integer, List<SeacraftSouthSeaBattleConfig>> rankBattleEntry : rankEntry.getValue().entrySet()) {
                    int rank = rankBattleEntry.getKey();
                    rankInfoList.add(new SeacraftSouthSeaBattleRankInfo(rank, rankBattleEntry.getValue()));
                }
            }
        }
        rankBattleListMap.values().forEach(a -> {
            a.values().forEach(e -> {
                e.sort((t1, t2) -> {
                    return Integer.compare(t1.getRank(), t2.getRank());
                });
            });
        });
    }

    public int getSEACRAFT_CRAFT_MATCH_NUM() {
        return SEACRAFT_CRAFT_MATCH_NUM;
    }

    public int getSEACRAFT_CRAFT_CHARGE_TIME() {
        return SEACRAFT_CRAFT_CHARGE_TIME;
    }

    public int getSEACRAFT_CRAFT_CHARGE_SINGLE_TIME() {
        return SEACRAFT_CRAFT_CHARGE_SINGLE_TIME;
    }

    public int getSEACRAFT_CRAFT_ATTACK_ITEM_ID() {
        return SEACRAFT_CRAFT_ATTACK_ITEM_ID;
    }

    public int getSEACRAFT_CRAFT_REWARD_COMBONUM() {
        return SEACRAFT_CRAFT_REWARD_COMBONUM;
    }

    public int getSEACRAFT_CRAFT_QUICKFIGHT_LIMIT_NUM() {
        return SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_NUM;
    }

    public int getSEACRAFT_CRAFT_QUICKFIGHT_LIMIT_VIP() {
        return SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_VIP;
    }

    public int getSEACRAFT_CRAFT_QUICKFIGHT_LIMIT_TIME_FINISH() {
        return SEACRAFT_CRAFT_QUICKFIGHT_LIMIT_TIME_FINISH;
    }

    public int getSEACRAFT_CRAFT_WRENCH_ITEM_ID() {
        return SEACRAFT_CRAFT_WRENCH_ITEM_ID;
    }

    public int getSEACRAFT_CRAFT_FIRE_ITEM_ID() {
        return SEACRAFT_CRAFT_FIRE_ITEM_ID;
    }

    public int getSEACRAFT_CRAFT_SHIP_DISPLAY_NUM() {
        return SEACRAFT_CRAFT_SHIP_DISPLAY_NUM;
    }

    public int getSEACRAFT_CRAFT_SCORE_ITEM_ID() {
        return SEACRAFT_CRAFT_SCORE_ITEM_ID;
    }

    public Long getSEACRAFT_CRAFT_DISTANCE() {
        return SEACRAFT_CRAFT_DISTANCE;
    }

    public static int getTeamNum() {
        return teamNum;
    }

    public int getSEACRAFT_CRAFT_CHARGE_SCORE() {
        return SEACRAFT_CRAFT_CHARGE_SCORE;
    }

    public int getSEACRAFT_CRAFT_KILL_REPORT() {
        return SEACRAFT_CRAFT_KILL_REPORT;
    }

    public int getSEACRAFT_CRAFT_SPEED_MIN() {
        return SEACRAFT_CRAFT_SPEED_MIN;
    }

    public int getGuessUnionNum() {
        return guessNum;
    }

    public static int getPubGribNum() {
        return pubGribNum;
    }

    public List<SeacraftSouthSeaShipConfig> getShipList() {
        return shipList;
    }

    public void setShipList(List<SeacraftSouthSeaShipConfig> shipList) {
        this.shipList = shipList;
    }

    public List<PeakSeacraftLastGuessConfig> getGuessList() {
        return guessList;
    }

    public void setGuessList(List<PeakSeacraftLastGuessConfig> guessList) {
        this.guessList = guessList;
    }

    public List<SeacraftSouthSeaFloorConfig> getFloorList() {
        return floorList;
    }

    public void setFloorList(List<SeacraftSouthSeaFloorConfig> floorList) {
        this.floorList = floorList;
    }

    public List<Integer> getAttackRankList() {
        return attackRankList;
    }

    public Map<Integer, SeacraftSouthSeaFloorConfig> getFloorMap() {
        return floorMap;
    }

    public List<Integer> getRepairParam() {
        return repairParam;
    }

    public void setBattleList(List<SeacraftSouthSeaBattleConfig> battleList) {
        this.battleList = battleList;
    }

    public List<SeacraftSouthSeaBattleConfig> getBattleList() {
        return battleList;
    }

    public List<PeakSeacraftDonateConfig> getSilverDonateList() {
        return silverDonateList;
    }

    public void setSilverDonateList(List<PeakSeacraftDonateConfig> silverDonateList) {
        this.silverDonateList = silverDonateList;
    }

    public Map<Integer, List<PeakSeacraftRoundScoreConfig>> getRoundScoreMap() {
        return roundScoreMap;
    }

    public void setRoundScoreMap(List<PeakSeacraftRoundScoreConfig> roundScoreList) {
        for (PeakSeacraftRoundScoreConfig scoreConfig : roundScoreList) {
            int key = getRoundScoreMapKey(scoreConfig.getArea(), scoreConfig.getRound());
            List<PeakSeacraftRoundScoreConfig> list = this.roundScoreMap.get(key);
            if (null == list) {
                list = new ArrayList<>();
                this.roundScoreMap.put(key, list);
            }
            list.add(scoreConfig);
        }
    }

    public int getSEACRAFT_CRAFT_SPEED_UP_LIMIT() {
        return SEACRAFT_CRAFT_SPEED_UP_LIMIT;
    }

    public List<Integer> getPaddleItemIdList() {
        return new ArrayList<>(paddleItemIdList);
    }

    /**
     * 是否是船桨道具
     *
     * @return
     */
    public boolean hasPaddleId(int propId) {
        return paddleItemIdList.contains(propId);
    }

    /**
     * 获取击杀奖励
     *
     * @param round        当前轮次
     * @param type         1突袭 2进攻
     * @param rank
     * @param winStreakNum
     * @return
     */
    public int getWinStreakReward(int round, int type, int rank, int winStreakNum) {
        SeacraftSouthSeaBattleConfig battleConfig = null;
        Map<Integer, List<SeacraftSouthSeaBattleRankInfo>> roundMap = rankBattleListMap.get(round);
        if(roundMap != null){
            List<SeacraftSouthSeaBattleRankInfo> rankBattleList = roundMap.get(type);
            if (rankBattleList != null) {
                for (SeacraftSouthSeaBattleRankInfo item : rankBattleList) {
                    if (rank <= item.getRank()) {
                        for (SeacraftSouthSeaBattleConfig tempBattleConfig : item.getBattleList()) {
                            battleConfig = tempBattleConfig;
                            if ((winStreakNum / SEACRAFT_CRAFT_REWARD_COMBONUM) <= tempBattleConfig.getVictoryTime()) {
                                break;
                            }
                        }
                        break;
                    }
                    //保底有一个最后的配置
                    battleConfig = item.getBattleList().get(item.getBattleList().size() - 1);
                }
            }
            if (battleConfig != null) {
                return battleConfig.getAward();
            }
        }
        return 0;
    }

    /**
     * @param propId
     * @return
     */
    public String getSpeedParam(int propId) {
        int index = paddleItemIdList.indexOf(propId);
        if (index >= 0) {
            return paddleItemParamList.get(index);
        }
        return "";
    }

    private void calcStageAndRound() {
        if (curRound > this.roundTimeList.size()) {
            return;
        }
        long nowTime = DateHelper.getCurrentSecond();
        if (nowTime >= nextRoundTime) {
            int round = 0;
            long nextTime = 0;
            long registrationEndTime = activityInfo.getBeginTime() + this.registrationEndTime;
            if (nowTime >= registrationEndTime) {
                round++;
                for (Integer[] config : this.roundTimeList) {
                    long endTime = config[1] + activityInfo.getBeginTime();
                    if (nowTime >= endTime) {
                        round++;
                    } else {
                        nextTime = endTime;
                        break;
                    }
                }
            } else {
                nextTime = registrationEndTime;
            }

            curRound = round;
            nextRoundTime = nextTime;
        }
    }

    public int getCurRound() {
        calcStageAndRound();
        return curRound;
    }

    public static int comparator(int patronsId1, long earn1, long addPlus1, int patronsId2, long earn2, long addPlus2) {
        long value1 = earn1 * (1000 + addPlus1) / 1000;
        long value2 = earn2 * (1000 + addPlus2) / 1000;
        if (value1 == value2) {
            return Long.compare(patronsId2, patronsId1);
        }
        return Long.compare(value2, value1);
    }

    /**
     * 本轮每组晋级下一海域人数
     *
     * @return
     */
    public int thisRoundNexAreaPromotionNum(int round) {
        int promotionNum = 0;
        if (this != null && round > 0) {
            if (round <= this.roundTimeList.size()) {
                Integer[] config = this.roundTimeList.get(round - 1);
                promotionNum = config[2];
            } else {
                // 最后一回合默认 晋级一个
                promotionNum = 1;
            }
        }
        return promotionNum;
    }

    /**
     * 报名期名单数
     */
    public int getRegistrationNum() {
        return Math.toIntExact(this.pretimeList.get(2));
    }

    /**
     * 是否是捐献期
     *
     * @return
     */
    public boolean isPrepareTime() {
        if (isPrepareTimeRound1()) {
            return true;
        }
        int now = DateHelper.getCurrentSecond();
        for (int i = 0; i < this.roundTimeList.size() - 1; i++) {
            // 比赛期间的捐献期
            long endTimeRound1 = activityInfo.getBeginTime() + this.roundTimeList.get(i)[1];
            long startTimeRound2 = activityInfo.getBeginTime() + this.roundTimeList.get(i+1)[0];
            if(endTimeRound1 <= now && now < startTimeRound2){
                return true;
            }
        }
        return false;
    }

    /**
     * 南海丝路 第一回合的备战期
     *
     * @return
     */
    public boolean isPrepareTimeRound1() {
        if(activityInfo == null){
            return false;
        }
        int now = DateHelper.getCurrentSecond();
        if(activityInfo.getBeginTime() + this.pretimeList.get(0) <= now && now < activityInfo.getBeginTime() + this.pretimeList.get(1)){
            return true;
        }
        return false;
    }


    /**
     * 南海丝路 是否开启
     *
     * @return
     */
    public boolean isOpenTime() {
        int curRound = getCurRound();
        if (curRound == 0 || this.roundTimeList.size() < curRound) {
            return false;
        }
        Integer[] config = this.roundTimeList.get(curRound - 1);
        long openTime = config[0] + activityInfo.getBeginTime();
        long endTime = config[1] + activityInfo.getBeginTime();
        int now = DateHelper.getCurrentSecond();
        if (now >= openTime && now < endTime) {
            return true;
        }
        return false;
    }

    /**
     * 南海丝路 是否可膜拜
     *
     * @return
     */
    public boolean canWorship() {
        if (getCurRound() > getMaxRoundCount()) {
            return true;
        }
        return false;
    }

    public int getGroupPerNum() {
        return GROUP_PERNUM;
    }

    public int getSEACRAFT_CRAFT_DONATE_ITEMS() {
        return SEACRAFT_CRAFT_DONATE_ITEMS;
    }

    public SeacraftSouthSeaShipConfig getShipConfig(int totalExp) {
        SeacraftSouthSeaShipConfig config = null;
        for (SeacraftSouthSeaShipConfig item : shipList) {
            config = item;
            if (totalExp < item.getExp()) {
                break;
            }
        }
        return config;
    }

    private int getRoundScoreMapKey(int area, int round) {
        return area * 100 + round;
    }

    public int getRoundGroupScoreByRank(int area, int round, int rank) {
        int key = getRoundScoreMapKey(area, round);
        if (roundScoreMap.containsKey(key)) {
            for (PeakSeacraftRoundScoreConfig scoreConfig : roundScoreMap.get(key)) {
                if (rank <= scoreConfig.getRank()) {
                    return scoreConfig.getScore();
                }
            }
        }
        return 0;
    }

    /**
     * 获得击败门客积分
     */
    public int getAttackPatronsScore(int area) {
        if (area <= 0 || area > this.roundTimeList.size()) {
            return 0;
        }
        return this.roundTimeList.get(area - 1)[3];
    }

    /**
     * 击败门客扣除船只耐久
     */
    public int getSEACRAFT_CRAFT_KILL_POINT() {
        return SEACRAFT_CRAFT_KILL_POINT;
    }

    public int getSEACRAFT_CRAFT_SHIP_NUM() {
        return SEACRAFT_CRAFT_SHIP_NUM;
    }

    public int getSEACRAFT_CRAFT_TALK_NUM() {
        return SEACRAFT_CRAFT_TALK_NUM;
    }

    public int getMaxRoundCount() {
        return roundTimeList.size();
    }

    public String getWORSHIP_REWARD() {
        return WORSHIP_REWARD;
    }

    /**
     * 根据排名获得玩家猜中的档位
     */
    public int getGuessConfigId(List<Integer> rankList) {
        PeakSeacraftLastGuessConfig rewardConfig = null;
        for (PeakSeacraftLastGuessConfig guessConfig : guessList) {
            rewardConfig = guessConfig;
            boolean isGuess = true;
            for (Integer guessRank : guessConfig.getGuessRankList()) {
                if (!rankList.contains(guessRank)) {
                    isGuess = false;
                    break;
                }
            }
            if (isGuess) {
                break;
            }
        }

        return rewardConfig.getId();
    }

    public boolean isShipMaxLevel(int totalExp) {
        if (shipList.isEmpty()) {
            return true;
        }
        SeacraftSouthSeaShipConfig lastConfig = shipList.get(shipList.size() - 1);
        if (getShipConfig(totalExp).equals(lastConfig)) {
            return true;
        }
        return false;
    }
}
